/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

import Model.Terms;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * Display all data in a table form, from the loans table
 */

public class SelectPrecompServlet extends HttpServlet {

    /**
 * Display all data in a table form, from the loans table
 */
    private String loantype;
    private Terms term = new Terms();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       java.sql.Connection con = DBConnector.connect();
       
        
        try{
       
        String clienttype = request.getParameter("clienttype");
        String subtype = request.getParameter("subtype");
        loantype = request.getParameter("loantype");
        Float pn=0f;
        int terms = 0;
        String precompno = request.getParameter("precompno");
        String firstname="",lastname="",middlename="";
            
        
            
                PreparedStatement ps = con.prepareStatement
                        ("Select *"
                        + "from precomp where precompno='"+precompno+"'");
                
                
                ResultSet rs = ps.executeQuery();
                while(rs.next())
                {
                    
                    terms = rs.getInt("terms");
                    pn = rs.getFloat("pnmonth");
                    term.setfLessui(rs.getFloat("ui"));
                    term.setfServicecharge(rs.getFloat("service"));
                    term.setfEvat(rs.getFloat("evat"));
                    term.setfDocs(rs.getFloat("doc"));
                    term.setfCollectionfee(rs.getFloat("collection"));
                    term.setfProcessingfee(rs.getFloat("process"));
                    term.setfBankcharge(rs.getFloat("bankcharge"));
                    term.setfNotaryfee(rs.getFloat("notary"));
                    term.setfLbccharge(rs.getFloat("lbc"));
                    term.setfCashbound(rs.getFloat("cashbound"));
                    firstname = rs.getString("firstname");
                    lastname = rs.getString("lastname");
                    middlename=rs.getString("middlename");
                }
                float loan= terms * pn;
                HttpSession session = request.getSession(true);
                session.setAttribute("terms",term);
                response.sendRedirect("precomputation.jsp?clienttype="+clienttype+"&loantype="+loantype+"&subtype="+subtype+"&terms="+terms+"&pn="+pn+"&loans="+loan+"&precompno="+precompno+"&firstname="+firstname+"&lastname="+lastname+"&middlename="+middlename);
            
        }catch(SQLException e)
        {
            System.out.println(e); 
           
        }
    

    }
  
}
